<template>
    <view class="">
        <view class="background"></view>
        <navView navTitle="员工列表" backgroundColor="#008efe" titleColor="#fff" :isBack="true">
        </navView>
        <view class="project-box">
            <view class="project-list2">
                <view class="project-card" v-for="(user, index) in userlist" :key="index"
                    @tap="$navTo('/pages/user/detail?id=' + user.id)">
                    <!-- 项目名称和状态 -->
                    <view class="project-header">
                        <text>{{ user.name }}</text>
                        <text :class="[
                                'status-tag', 
                                user.role == 1 ? 'completed' : 
                                user.role == 2 ? 'ongoing' : 
                                user.role == 3 ? 'not-started' : 
                                user.role == 4 ? 'ongoing' : 
                                user.role == 5 ? 'ongoing' : 
                                user.role == 6 ? 'ongoing' : '']">
                            {{ user.staffrole.name }}
                        </text>
                    </view>
                    <!-- 人员信息 -->
                    <view class="project-detail">
                        <text>{{ user.educational || "暂无学历"}}</text>
                        <text>{{ user.mobile || "暂无电话"}}</text>
                        <text>{{ user.salary || "暂无薪资" }}</text>

                    </view>
                    <view class="project-price">
                        <view class="item-line">
                            入职日期：<text class="highlight">{{ user.joiningdate || "暂未入职"}}</text>
                        </view>
                        <view class="item-line">
                            试用期合同：
                            <text class="status-tag warning" v-if="user.is_trial == 0">未签订</text>
                            <text class="status-tag success" v-else>已签订</text>
                        </view>
                        <view class="item-line">
                            正式合同：
                            <text class="status-tag warning" v-if="user.is_join == 0">未签订</text>
                            <text class="status-tag success" v-else>已签订</text>
                        </view>
                    </view>
                </view>
            </view>
            <view v-if="isLoading" class="loading-text">加载中...</view>
            <view v-if="isNoMore && userlist.length > 0" class="no-more-text">已经到底啦~</view>
        </view>
        <image @tap="$navTo('/pages/user/adduser')" class="addimg" src="https://hfd.bjlzkj.com/static/user/add.png"
            mode=""></image>
    </view>
</template>

<script>
export default {
    data() {
        return {
            userlist: [{
                name: '项目一',
                status: 1,
                phone: '13025689523',
            },
            {
                name: '项目二',
                status: 2,
                phone: '15862140021',
            },
            {
                name: '项目三',
                status: 3,
                phone: '15862140021',
            },
            ],
            user_status: 2,
            currentPage: 1,
            totalPages: 1,
            isLoading: false,
            isNoMore: false
        }
    },
    // 添加生命周期钩子
    onReachBottom() {
        if (!this.isLoading && !this.isNoMore) {
            this.getUserList();
        }
    },
    onShow() {
        this.getUserList();
    },
    methods: {
        getUserList() {
            if (this.currentPage === 1) {
                this.isNoMore = false;
            }

            this.isLoading = true;
            this.$request('/addons/qingdong/staff/getStaffLists', 'GET', {
                page: this.currentPage,
                per_page: 10
            }).then(res => {
                if (res.data.data && res.data.data.length > 0) {
                    this.userlist = this.currentPage === 1
                        ? res.data.data
                        : [...this.userlist, ...res.data.data];

                    this.totalPages = res.data.last_page || 1;
                    this.isNoMore = this.currentPage >= this.totalPages;
                    this.currentPage++;
                } else {
                    this.isNoMore = true;
                    if (this.currentPage === 1) this.userlist = [];
                }
            }).finally(() => {
                this.isLoading = false;
            });
        }
    }
}
</script>

<style lang="scss">
.loading-text,
.no-more-text {
    text-align: center;
    padding: 20rpx;
    color: #999;
    font-size: 26rpx;
}
.background {
    background: #f5f6f9;
    width: 100%;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: -1;
}

.topBox {
    width: 100%;
    position: fixed;
    left: 0;

    .stateList {
        width: 100%;
        background: #fff;
        display: flex;
        align-items: center;
        justify-content: space-around;

        .items {
            font-weight: bold;
            font-size: 30rpx;
            color: #008EFE;
            position: relative;
            padding: 20rpx 0;

            .tiao {
                width: 38rpx;
                height: 4rpx;
                background: #64AFFF;
                border-radius: 2rpx 2rpx 2rpx 2rpx;
                position: absolute;
                bottom: 0rpx;
                left: 50%;
                transform: translate(-50%);
            }
        }

        .item {
            font-size: 30rpx;
            color: #AFAFB2;
            padding: 20rpx 0;
        }
    }
}


.project-box {
    padding: 20rpx;
    box-sizing: border-box;

    .project-list2 {

        .project-title {
            display: flex;
            align-items: center;
            justify-content: space-between;
            background: #e5f3ff;
            padding: 26rpx 20rpx;
            box-sizing: border-box;
            border-top-left-radius: 16rpx;
            border-top-right-radius: 16rpx;
            font-weight: 400;
            font-size: 24rpx;
            color: #B0B0B0;

            .tite {
                font-weight: bold;
                font-size: 30rpx;
                color: #333333;
            }
        }

        .project-card {
            overflow: hidden;
            margin-bottom: 20rpx;
            padding: 20rpx;
            margin: 20rpx 0;
            border-radius: 16rpx;
            background-color: #fff;

            .project-header {
                display: flex;
                justify-content: space-between;
                align-items: center;
                margin-bottom: 10rpx;

                text {
                    font-size: 32rpx;
                    font-weight: bold;
                }

                .status-tag {
                    border-radius: 10rpx;
                    padding: 6rpx 12rpx;
                    font-size: 24rpx;
                    font-weight: bold;
                    color: #fff;

                    &.completed {
                        background-color: #FFAA00;
                    }

                    &.ongoing {
                        background-color: #007aff;
                    }

                    &.not-started {
                        background-color: #ff3a3a;
                    }
                }
            }

            .project-price {
                font-weight: 400;
                font-size: 24rpx;
                color: #7D7D7D;

                text {
                    color: #000000;
                }
            }

            .project-detail {
                display: grid;
                grid-template-columns: repeat(3, 0.19fr);
                gap: 16rpx;
                padding: 20rpx 0;
                font-size: 24rpx;
                color: #7f7f7f;
                .info-item {
                    padding: 16rpx;
                    border-radius: 8rpx;
                    background: #f8f9fb;
                    display: flex;
                    align-items: center;
                    
                    &.accent {
                        background: #e8f4ff;
                        .label { color: #008EFF; }
                    }
                    &.phone {
                        background: #f0faff;
                        .icon {
                            width: 32rpx;
                            height: 32rpx;
                            margin-right: 8rpx;
                        }
                    }
                    &.salary {
                        background: #fff4e5;
                        .value { color: #FF5722; }
                    }
                    
                    .label {
                        font-size: 24rpx;
                        color: #666;
                        margin-right: 8rpx;
                    }
                    .value {
                        font-size: 28rpx;
                        font-weight: 500;
                        color: #333;
                    }
                }
            }

            .project-price {
                display: flex;
                flex-direction: column;
                gap: 12rpx;
                margin-top: 24rpx;
                padding-top: 24rpx;
                border-top: 1rpx dashed #eee;

                .item-line {
                    display: flex;
                    align-items: center;
                    justify-content: space-between;
                    font-size: 26rpx;
                    color: #666;
                    
                    .highlight {
                        color: #008EFF;
                        font-weight: 500;
                    }
                    
                    .status-tag {
                        padding: 4rpx 16rpx;
                        border-radius: 20rpx;
                        font-size: 24rpx;
                        
                        &.success {
                            background: #e8f5e9;
                            color: #00C853;
                        }
                        &.warning {
                            background: #fff3e0;
                            color: #FF9800;
                        }
                    }
                }
            }
            .tab-bar {
                display: flex;
                justify-content: space-between;
                margin-bottom: 20rpx;

                .tab-item {
                    width: 20%;
                    text-align: center;
                    padding: 8rpx 0;
                    background-color: #e0f1ff;
                    border-radius: 10rpx;
                    color: #007aff;
                    font-size: 24rpx;
                }
            }

            .service-evaluation {
                display: flex;
                justify-content: space-between;
                align-items: center;
                font-size: 24rpx;
                color: #E56C2B;
                background-color: #F5F5F5;
                padding: 10rpx 10rpx;
                box-sizing: border-box;
                border-radius: 10rpx;

                .right {
                    width: 8rpx;
                    height: 16rpx;
                    margin-left: 20rpx;
                }
            }
        }
    }
}

/* 弹出层的整体样式 */
.popup-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: fixed;
    bottom: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    /* 半透明背景 */
    transition: all 0.3s ease;
    /* 添加动画 */
}

.popup-box.hidden {
    transform: translateY(100%);
}

.popup-content {
    background-color: #fff;
    border-radius: 16px 16px 0 0;
    padding: 20px;
    width: 80%;
    max-width: 400px;
    box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
}

.popup-title {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 10px;
}

.popup-item {
    font-size: 14px;
    margin-bottom: 10px;
}

.popup-button {
    width: 100%;
    height: 40px;
    border-radius: 20px;
    background-color: #1890ff;
    color: #fff;
    font-size: 16px;
    margin-top: 20px;
}
.addimg {
    width: 96rpx;
    height: 96rpx;
    position: fixed;
    bottom: 120rpx;
    right: 40rpx;
    background-color: #fff;
}
</style>